#ifndef HTTPMGR_H
#define HTTPMGR_H
#include "singleton.h"
#include <QString>
#include <QUrl>
#include <QObject>
#include <QNetworkAccessManager>
#include <QJsonObject>
#include <QJsonDocument>

class HttpMgr: public QObject, public Singleton<HttpMgr>,
                public std::enable_shared_from_this<HttpMgr>
{
    Q_OBJECT
public:
    ~HttpMgr();
/******************************************************************************
 *
 * @file       httpmgr.h
 * @brief      用于发送http的post请求
 *
 * @author     wangzn2016
 * @date       2024/11/19
 * @history
 *****************************************************************************/
    void PostHttpReq(QUrl url, QJsonObject json, ReqId req_id, Modules mod);

private:
    // 用于基类singleton的_instance成员能够访问HttpMgr的构造函数(初始化)
    friend class Singleton<HttpMgr>;
    HttpMgr();
    QNetworkAccessManager _manager;

private slots:
    void slot_http_finish(ReqId id, QString res, ErrorCodes err, Modules mod);

signals:
/******************************************************************************
 *
 * @file       httpmgr.h
 * @brief      当http发送完后，会通过此信号来通知其它模块
 *
 * @author     wangzn2016
 * @date       2024/11/20
 * @history
 *****************************************************************************/
    void sig_http_finish(ReqId req_id, QString res, ErrorCodes err, Modules mod);
/******************************************************************************
 *
 * @file       httpmgr.h
 * @brief      此信号连接注册模块的槽函数，注册模块的槽函数会解析
 *             收到的json数据
 *
 * @author     wangzn2016
 * @date       2024/11/21
 * @history
 *****************************************************************************/
    void sig_reg_mod_finish(ReqId id, QString res, ErrorCodes err);
};

#endif // HTTPMGR_H
